package com.zicheng.thread.demo;

import com.easyooo.framework.common.util.JsonUtils;

import java.util.Map;

/**
 * 在继承的基础之上,去查看更多关于Thread的信息
 *
 * @author wzy
 */
public class DemoTaskTwo extends Thread {

    public void sayYes() {
        System.out.println("yes,demoTask1 is running");
    }

    public void currentThreadNow() {
        System.out.println(Thread.currentThread().getName() + " : " + Thread.currentThread().getId() + " is running");
    }

    public void seeStackTrace() {
        StackTraceElement[] stackTrace = this.getStackTrace();
        for (StackTraceElement stackTraceElement : stackTrace) {
            System.out.println(stackTraceElement.toString());
        }
        Map<String, Object> jsonMap = JsonUtils.toJsonMap(stackTrace);
        for (Map.Entry<String, Object> entry : jsonMap.entrySet()) {
            System.out.println(entry.getKey() + " : " + entry.getValue());
        }
    }

    @Override
    public void run() {
        sayYes();
        currentThreadNow();
        seeStackTrace();
    }
}
